package com.cyys.modules.system.controller.log;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cyys.common.annotation.SystemLog;
import com.cyys.common.ql.AR;
import com.cyys.common.ql.JSONData;
import com.cyys.modules.core.controller.BaseAction;
import com.cyys.modules.system.model.log.Log;
import com.cyys.modules.system.service.log.LogService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

@Controller
@RequestMapping("/sys/log")
public class LogAction extends BaseAction {

	@Resource
	private LogService logService;

	@GetMapping("/list")
	@RequiresPermissions("sys:log:list")
	public String list(Model model) {
		return "module/system/log/log-list";
	}

	@GetMapping("/logList")
	@RequiresPermissions("sys:loginlog")
	public String logList(Model model) {
		return "module/system/log/login-log-list";
	}

	@ResponseBody
	@PostMapping("/del/deleteById")
	@RequiresPermissions("sys:log:del")
	@SystemLog(module = "系统设置", methods = "日志管理-删除日志管理")
	public AR deleteById(String id)  {
		return logService.deleteById(id);
	}

	@ResponseBody
	@PostMapping("/del/deleteByIds")
	@RequiresPermissions("sys:log:del")
	@SystemLog(module = "系统设置", methods = "日志管理-批量删除日志管理")
	public AR deleteByIds(String ids)  {
		return logService.deleteBatchIds(ids);
	}

	@ResponseBody
	@PostMapping("/list/logList")
	@RequiresPermissions("sys:log:list")
	// @SystemLog(module="系统设置",methods="日志管理-查询日志管理")
	public String loglist(Log log, Page page)  {
		return JSONData.toLayerData(logService.list(page , new QueryWrapper(log),true));
	}
}
